package com.skt.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.skt.common.annotation.Log;
import com.skt.common.core.controller.BaseController;
import com.skt.common.core.domain.AjaxResult;
import com.skt.common.enums.BusinessType;
import com.skt.manage.domain.Announcements;
import com.skt.manage.service.IAnnouncementsService;
import com.skt.common.utils.poi.ExcelUtil;
import com.skt.common.core.page.TableDataInfo;

/**
 * 公告新闻管理Controller
 * 
 * @author ffbaby
 * @date 2025-02-25
 */
@RestController
@RequestMapping("/manage/announcements")
public class AnnouncementsController extends BaseController
{
    @Autowired
    private IAnnouncementsService announcementsService;

    /**
     * 查询公告新闻管理列表
     */
//    @PreAuthorize("@ss.hasPermi('manage:announcements:list')")
    @GetMapping("/list")
    public TableDataInfo list(Announcements announcements)
    {
        startPage();
        List<Announcements> list = announcementsService.selectAnnouncementsList(announcements);
        return getDataTable(list);
    }

    /**
     * 导出公告新闻管理列表
     */
    @PreAuthorize("@ss.hasPermi('manage:announcements:export')")
    @Log(title = "公告新闻管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Announcements announcements)
    {
        List<Announcements> list = announcementsService.selectAnnouncementsList(announcements);
        ExcelUtil<Announcements> util = new ExcelUtil<Announcements>(Announcements.class);
        util.exportExcel(response, list, "公告新闻管理数据");
    }

    /**
     * 获取公告新闻管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:announcements:query')")
    @GetMapping(value = "/{announcementId}")
    public AjaxResult getInfo(@PathVariable("announcementId") Long announcementId)
    {
        return success(announcementsService.selectAnnouncementsByAnnouncementId(announcementId));
    }

    /**
     * 新增公告新闻管理
     */
    @PreAuthorize("@ss.hasPermi('manage:announcements:add')")
    @Log(title = "公告新闻管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Announcements announcements)
    {
        return toAjax(announcementsService.insertAnnouncements(announcements));
    }

    /**
     * 修改公告新闻管理
     */
    @PreAuthorize("@ss.hasPermi('manage:announcements:edit')")
    @Log(title = "公告新闻管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Announcements announcements)
    {
        return toAjax(announcementsService.updateAnnouncements(announcements));
    }

    /**
     * 删除公告新闻管理
     */
    @PreAuthorize("@ss.hasPermi('manage:announcements:remove')")
    @Log(title = "公告新闻管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{announcementIds}")
    public AjaxResult remove(@PathVariable Long[] announcementIds)
    {
        return toAjax(announcementsService.deleteAnnouncementsByAnnouncementIds(announcementIds));
    }
}
